import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/bean/repair_list_entity.dart';
import 'package:xin_nuo_pda/routes/Routes.dart';
import 'package:xin_nuo_pda/utils/string_extension.dart';
import 'package:xin_nuo_pda/values/colors.dart';
import 'package:xin_nuo_pda/views/edittext/TitleEditText.dart';

import 'EquipmentRepairListController.dart';

class EquipmentRepairListPage extends StatelessWidget {
  final controller = Get.put(EquipmentRepairListController());
  final state = Get.find<EquipmentRepairListController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(state.title),
          actions: [
            Align(
              alignment: Alignment.centerRight,
              child: Container(
                height: 36,
                padding: EdgeInsets.fromLTRB(4, 0, 4, 0),
                margin: EdgeInsets.only(right: 8),
                child: OutlinedButton(
                  style: OutlinedButton.styleFrom(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(8.0),
                    ),
                    side: BorderSide(width: 1, color: Colors.white),
                  ),
                  onPressed: () {controller.initList();},
                  child: Text(
                    "刷新",
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
            )
          ],
        ),
        body: SingleChildScrollView(
          child: Container(
            child: Column(children: [
              TitleEditText(
                "设备ID*:",
                "请扫描设备ID",
                (value) {
                  controller.initList();
                },
                controller: state.eqpController,
              ),
              SizedBox(
                height: 1,
              ),
              GetBuilder<EquipmentRepairListController>(
                  builder: (controller) => Column(
                        children: [
                          GetBuilder<EquipmentRepairListController>(
                            builder: (controller) => Container(
                                height: 48,
                                padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
                                color: Colors.white,
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        "维修列表*:",
                                        style: TextStyle(
                                            color: theme_blue.toColor()),
                                      ),
                                      flex: 3,
                                    ),
                                    // Expanded(
                                    //     flex: 7,
                                    //     child: Container(
                                    //         child: Row(
                                    //       children: [
                                    //         Container(
                                    //           padding: EdgeInsets.only(left: 8),
                                    //           height: 32,
                                    //           decoration: BoxDecoration(
                                    //             border: new Border.all(
                                    //                 width: 1.0,
                                    //                 color: Colors.grey),
                                    //           ),
                                    //           child:
                                    //               DropdownButtonHideUnderline(
                                    //             child: DropdownButton(
                                    //               value:
                                    //                   state.selectDefectValue,
                                    //               items: [
                                    //                 DropdownMenuItem(
                                    //                   child: Text('未完成'),
                                    //                   value: 'UNCOMPLETE',
                                    //                 ),
                                    //                 DropdownMenuItem(
                                    //                   child: Text('已完成'),
                                    //                   value: 'COMPLETE',
                                    //                 )
                                    //               ],
                                    //               onChanged: (value) {
                                    //                 controller
                                    //                     .updateSelectDefectValue(
                                    //                         value);
                                    //               },
                                    //             ),
                                    //           ),
                                    //         )
                                    //       ],
                                    //     ))),
                                  ],
                                )),
                            id: state.dropDownId,
                          ),
                          Table(
                            defaultVerticalAlignment:
                                TableCellVerticalAlignment.middle,
                            columnWidths: {
                              //列宽
                              0: FlexColumnWidth(2.0),
                              1: FlexColumnWidth(2.0),
                              2: FlexColumnWidth(2.0),
                              3: FlexColumnWidth(1.0),
                            },
                            border: TableBorder.all(
                              color: Colors.grey,
                              width: 1.0,
                              style: BorderStyle.solid,
                            ),
                            children: getTableRow(context),
                          ),
                        ],
                      ),id: state.repairListId,),
            ]),
          ),
        ));
  }

  List<TableRow> getTableRow(BuildContext context) {
    List<TableRow> tempView = [];
    tempView.add(TableRow(
        children: [
          //增加行高
          SizedBox(
            height: 60,
            child: Align(
              alignment: Alignment.center,
              child: Text(
                '报修记录ID/报修工号/报修人',
                style: TextStyle(
                  color: theme_blue.toColor(),
                ),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '设备ID',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '报修时间',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: Text(
              '状态',
              style: TextStyle(
                color: theme_blue.toColor(),
              ),
            ),
          ),
        ],
        //第一行样式 添加背景色
        decoration: BoxDecoration(
          color: table_head.toColor(),
        )));
    for (int i = 0; i < state.repairList.length; i++) {
      RepairListREPAIRLIST element = state.repairList[i];
      tempView.add(TableRow(children: [
        //增加行高
        SizedBox(
          height: 60,
          child: Align(
            alignment: Alignment.center,
            child: Material(
              color: Colors.white,
              child: Ink(
                child: InkWell(
                    onTap: () {
                      switch(state.where){
                        case "EQP":
                          Get.toNamed(Routes.EquipmentRepairDetails,arguments: element.sHEETID);
                          break;
                        case "PE":
                          Get.toNamed(Routes.PeConfirm,arguments: element.sHEETID);
                          break;
                        case "QA":
                          Get.toNamed(Routes.QaConfirm,arguments: element.sHEETID);
                          break;
                      }

                    },
                    child: Text(
                        (element.sHEETID ?? '') + '/' + (element.tROUBLEREPORTER ?? '') + '/' + (element.tROUBLEREPORTERNAME ?? ''),
                      style: TextStyle(
                        color: text_black.toColor(),
                      ),
                    )),
              ) ,
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            element.eQUIPMENTID ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            element.tROUBLETIME ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: Text(
            element.STATUS ?? '',
            style: TextStyle(
              color: text_black.toColor(),
            ),
          ),
        ),
      ]));
    }
    return tempView;
  }
}
